feat: add support for oauth whitelist file (#817)#826
feat: add support for oauth whitelist file (#817)#826djedditt wants to merge 1 commit intotinyauthapp:mainfrom
Conversation
📝 WalkthroughWalkthroughThis change introduces file-based OAuth whitelist support, enabling whitelists to be loaded from a filesystem path ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Review rate limit: 2/3 reviews remaining, refill in 20 minutes. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/utils/string_utils_test.go (1)
4-4: Harden temp-file test setup to avoid collisions and OS-specific assertions.Line 69 and Line 87 use fixed
/tmp/...paths, and Line 88 asserts an OS-specific error string. Prefert.TempDir()+errors.Is(err, os.ErrNotExist)for stable tests.Proposed test hardening diff
import ( + "errors" "os" + "path/filepath" "testing" @@ func TestGetStringList(t *testing.T) { - file, err := os.Create("/tmp/tinyauth_list_test_file") - assert.NilError(t, err) - - _, err = file.WriteString(" third@example.com \n\n fourth@example.com \n") - assert.NilError(t, err) - - err = file.Close() - assert.NilError(t, err) - defer os.Remove("/tmp/tinyauth_list_test_file") + tmpDir := t.TempDir() + filePath := filepath.Join(tmpDir, "tinyauth_list_test_file") + err := os.WriteFile(filePath, []byte(" third@example.com \n\n fourth@example.com \n"), 0o600) + assert.NilError(t, err) - values, err := utils.GetStringList([]string{" first@example.com ", "", "second@example.com"}, "/tmp/tinyauth_list_test_file") + values, err := utils.GetStringList([]string{" first@example.com ", "", "second@example.com"}, filePath) assert.NilError(t, err) assert.DeepEqual(t, []string{"first@example.com", "second@example.com", "third@example.com", "fourth@example.com"}, values) @@ - values, err = utils.GetStringList(nil, "/tmp/non_existing_list_file") - assert.ErrorContains(t, err, "no such file or directory") + values, err = utils.GetStringList(nil, filepath.Join(tmpDir, "non_existing_list_file")) + assert.Assert(t, errors.Is(err, os.ErrNotExist)) assert.DeepEqual(t, []string{}, values) }Also applies to: 69-90
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/utils/string_utils_test.go` at line 4, Tests in internal/utils/string_utils_test.go use hard-coded /tmp/... paths and assert OS-specific error text; update the failing test setup to use t.TempDir() to create unique temp directories and files, construct expected paths relative to that temp dir instead of using fixed /tmp paths, and replace string equality on the error with errors.Is(err, os.ErrNotExist) (importing "errors" and "os" as needed). Locate the test function(s) that reference the fixed paths and the error assertion (search for the hard-coded "/tmp/" literals and the assertion comparing err.Error()) and modify them to use t.TempDir(), build paths with filepath.Join, and use errors.Is for the non-existence check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@internal/utils/string_utils_test.go`:
- Line 4: Tests in internal/utils/string_utils_test.go use hard-coded /tmp/...
paths and assert OS-specific error text; update the failing test setup to use
t.TempDir() to create unique temp directories and files, construct expected
paths relative to that temp dir instead of using fixed /tmp paths, and replace
string equality on the error with errors.Is(err, os.ErrNotExist) (importing
"errors" and "os" as needed). Locate the test function(s) that reference the
fixed paths and the error assertion (search for the hard-coded "/tmp/" literals
and the assertion comparing err.Error()) and modify them to use t.TempDir(),
build paths with filepath.Join, and use errors.Is for the non-existence check.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b5b80f72-6e46-43a7-abcc-42c066793a67
📒 Files selected for processing (7)
.env.exampleinternal/bootstrap/app_bootstrap.gointernal/bootstrap/service_bootstrap.gointernal/config/config.gointernal/utils/string_utils.gointernal/utils/string_utils_test.gointernal/utils/user_utils.go
Fixes #817.
Added
TINYAUTH_OAUTH_WHITELISTFILEsupport for loading whitelist entries from a file, merged with the existing inline whitelist config. This follows the same pattern as auth users/usersfile. Extracted shared inline/file parsing into reusable string utils.Summary by CodeRabbit
Release Notes